/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kylingroup.J2SE.Thread;

/**
 *
 * @author kylin
 */
public class TestThreadSynchronized3 implements Runnable{
    int b=100;
    public synchronized void method1() throws Exception{
        b=1000;
        Thread.sleep(5000);
        System.out.println("b="+b);
    }
//    public synchronized void method2() throws Exception{
//        Thread.sleep(2500);
//        b=2000;  
//    }
    public void method2() throws Exception{
        Thread.sleep(2500);
        b=2000;
    }
    public void run(){
        try{
            method1();
        }catch(Exception e){
            e.printStackTrace();
        }
    }
    public static void main(String args[]) throws Exception{
        TestThreadSynchronized3 t=new TestThreadSynchronized3();
        Thread th=new Thread(t);
        th.start();
        
        t.method2();
        System.out.println(t.b);
    }
}